/*
 * File:    IO.c
 * Project:	HobbyPilotFirmware (HPF)
 * Author:  Wouter van Verre
 *
 * Created on February 8, 2011, 9:42 PM
 */

#include "Header.h"

void initIO(void)
{
	// Set all pins to be output. Inputs can be configured later. 
	// This ensures that unused pins are configures as ouputs,
	// per Microchip recommendation.
 	TRISA = 0x00;
	TRISB = 0x00;
	TRISC = 0x00;
	TRISD = 0x00;
	TRISF = 0x00;

	LATA = 0x00;
	LATB = 0x00;
	LATC = 0x00;
	LATD = 0x00;
	LATF = 0x00;

	TRISB |= 0b0001110000001111;

    // Turn RF1 on
    LATFbits.LATF1 = 1;

    // Set up the UART1 module's alternate IO pins
    TRISCbits.TRISC13 = 0;      // Set U1ATX to be output
    TRISCbits.TRISC14 = 1;      // Set U1ARX to be input

	// Set up the UART2 module's IO pins
	TRISFbits.TRISF5 = 0;		// Set U2TX to be output
	TRISFbits.TRISF4 = 1;		// Set U2RX to be input
}

inline void toggleActivityLED(void)
{
    LATAbits.LATA11 = !PORTAbits.RA11;  // Toggle the state of the RA11 pin
}

inline void toggleYellowLED(void)
{
	LATFbits.LATF1 = !PORTFbits.RF1;	// Toggle the status of the RF1 pin
}

inline void toggleOrangleLED(void)
{
	LATFbits.LATF0 = !PORTFbits.RF0;	// Toggle the status of the RF0 pin
}

inline void turnOffYellowLED(void)
{
	LATFbits.LATF1 = 0;
}

inline void turnOffOrangeLED(void)
{
	LATFbits.LATF0 = 0;
}

inline void turnOnYellowLED(void)
{
	LATFbits.LATF1 = 1;
}

inline void turnOnOrangeLED(void)
{
	LATFbits.LATF0 = 1;
}
